package cn.wink.springcloud.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import java.util.UUID;

/**
 * @author xw
 * @date 2020-06-14 23:09
 */
/**
 * @EnableBinding 定义消息的推送管道
 */
@EnableBinding(Source.class)    //指定信道channel和exchange绑定
public class MessageProviderImpl implements MessageProvider {

    /**
     * 消息发送管道
     */
    @Autowired
    private MessageChannel output;

    @Override
    public String send() {
        String uuid = UUID.randomUUID().toString();
        System.out.println("uuid:"+uuid);
        output.send(MessageBuilder.withPayload(uuid).build());
        return uuid;
    }
}
